#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int countPrimes(int n)
    {
        if (n <= 1)
        {
            return 0;
        }

        std::vector<int> isPrime(n, 1);
        int count = 0;

        for (int i = 2; i < n; ++i)
        {
            if (isPrime[i] == 1)
            {
                ++count;
                for (int j = 2; i * j < n; ++j)
                {
                    isPrime[i * j] = 0;
                }
            }
        }

        return count;
    }
};